package com.xsh.service.impl;

import com.xsh.mapper.MenuMapper;
import com.xsh.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.Set;
@Service
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private MenuMapper menuMapper;

    @Override
    public Set<String> findByUsername(String username) {
        Set<String> permissionSet = menuMapper.selectPermissionByUsername(username);
        Set<String> allPermission = new HashSet<>();
        for (String s : permissionSet) {
            if (s == null) {
                continue;
            }
            String[] permissions = s.split(",");
            for (String permission : permissions) {
                allPermission.add(permission);
            }
        }
        return allPermission;
    }
}
